#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.56)
AC_INIT(palx, 0.3, palxex@gmail.com)
AC_CANONICAL_BUILD()
AC_CANONICAL_HOST()
AC_CANONICAL_TARGET() 
AM_INIT_AUTOMAKE

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AM_PROG_CC_C_O

dnl Check for Allegro Installed
AM_PATH_ALLEGRO(4.2.0)

dnl Check for boost lib
AX_BOOST_BASE([1.33])
#AX_BOOST_REGEX

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h memory.h stdint.h stdlib.h string.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T
AC_C_VOLATILE

dnl check for pkg-config
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)

dnl binio
binio_CFLAGS="`$PKG_CONFIG libbinio --cflags`"
AC_SUBST(binio_CFLAGS)

dnl adplug
adplug_LIBS="`$PKG_CONFIG adplug --libs`"
adplug_CFLAGS="`$PKG_CONFIG adplug --cflags`"
AC_SUBST(adplug_LIBS)
AC_SUBST(adplug_CFLAGS)

dnl freetype2
freetype2_LIBS="`freetype-config --libs`"
freetype2_CFLAGS="`freetype-config --cflags`"
AC_SUBST(freetype2_LIBS)
AC_SUBST(freetype2_CFLAGS)

#Features to enable/disable
AH_TEMPLATE(WITH_LUA,[Define to 1 to enable internal console, requires lua & its c++ binding])
AC_ARG_ENABLE(console,AC_HELP_STRING([--enable-console],[Enable console]),[
   AC_CHECK_HEADER(lua.h,have_lua_h=yes,)
   AC_CHECK_HEADER(luabind/luabind.h,have_luabind_h=yes,)
   AC_CHECK_LIB(readline,history_list,have_readline_lib=yes,)
   AC_CHECK_LIB(lua,luaL_openlibs,have_lua_lib=yes,)
   AC_CHECK_LIB(luabind,lua_tonumber,have_luabind_lib=yes,)

   if test x$enable_console = xno; then
     AC_MSG_RESULT([Console not enabled])
   elif test x$have_lua_lib = xyes -a x$have_lua_h = xyes -a x$have_luabind_lib=xyes -a x$have_luabind_h=xyes -a x$have_readline_lib=xyes; then
     lua_LIBS="$LIBS `$PKG_CONFIG lua --libs` -lreadline -lluabind"
     lua_CFLAGS="`$PKG_CONFIG lua --cflags` -I/usr/include/luabind"
     AC_DEFINE(WITH_LUA,1)
   else 
     AC_MSG_ERROR([Can't find curses, which is required for debug mode])
   fi
],)
AC_SUBST(lua_LIBS)
AC_SUBST(lua_CFLAGS)
AM_CONDITIONAL(LUA_CONSOLE, test "x$lua_LIBS" != "x")

dnl OSX build need iconv because not uses glibc
case "$target" in 
    *darwin*)
        iconv_LIBS="-liconv"
    ;;
esac
AC_SUBST(iconv_LIBS)

dnl Some stuff for the icon.
case "$target" in
    *-*-cygwin* | *-*-mingw32*)
       dnl Some stuff for the ico
       AC_CHECK_PROGS(WINDRES, windres, :)
    ;;
    *)
       WINDRES=":"
    ;;
esac
AM_CONDITIONAL(HAVE_WINDRES, test "x$WINDRES" != "x:")
AC_SUBST(WINDRES)
       

AC_CONFIG_FILES([Makefile
                 src/Makefile])
AC_OUTPUT
